package com.hitsoysauce.date20121229.launcher;

import java.util.Scanner;
import java.util.regex.MatchResult;

/**
 * 测试简单文本扫描器
 * @author liupj
 *
 */
public class TestScanner {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
//		
//		System.out.println("Please Input a Number:");
//		
//		System.out.println("Your have input " + sc.nextDouble());
		
	    String input = "1 fish 2 fish red fish blue fish";
	    Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
	    System.out.println(s.nextInt());
	    System.out.println(s.nextInt());
	    System.out.println(s.next());
	    System.out.println(s.next());
	    s.close(); 
	    
	    
	    System.out.println();
	    System.out.println();
	    System.out.println();
	    System.out.println();
	    
	    input = "1 fish 2 fish red fish blue fish";
	    s = new Scanner(input);
	    s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
	     
	    MatchResult result = s.match();
	    for (int i = 1; i<= result.groupCount(); i++) {
	    	System.out.println(result.group(i));
	    }
	    
	    s.close(); 
	    
	    
	    System.out.println();
	    
	    System.out.println(s.delimiter());
	    
	    s.reset();
	    System.out.println(s.delimiter());
	    
	    
	}

}
